package org.abettor.pushbox.map;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * 箱子的地图
 * 
 * @author jzh
 * 
 */
public class Boxmap {
	/**
	 * 把错误代码转换为说
	 * 
	 * @param errorCode
	 * @return
	 */
	public static String changeErrorCodeToStr(int errorCode) {
		switch (errorCode) {
		case MapCheckErrorCode.SUCCESS:
			return "成功的地图";
		case MapCheckErrorCode.NOPERSON:
			return "地图上没有人";
		case MapCheckErrorCode.BOXISEMPTY:
			return "地图上没有箱子";
		case MapCheckErrorCode.BRICISEMPTY:
			return "地图上没有砖头";
		case MapCheckErrorCode.BOXNOTEQUALSDEST:
			return "箱子和目标点不符";
		case MapCheckErrorCode.PATHNOTCLOSED:
			return "地图没有闭合";
		case MapCheckErrorCode.NOTINONECLOSED:
			return "没在一个闭合圈内";
		default:
			return "其他问题";
		}
	}

	// 用来显示地图发生错的类
	public static class MapCheckErrorCode {
		public static final int SUCCESS = 0;// 正确的地图
		public static final int NOPERSON = 1;// 没有人的错误
		public static final int BOXISEMPTY = 2;// 没有箱子的错误
		public static final int BRICISEMPTY = 3;// 没有砖头
		public static final int BOXNOTEQUALSDEST = 4;// 目标和箱子数不符
		public static final int PATHNOTCLOSED = 5;// 地图没有封闭
		public static final int NOTINONECLOSED = 6;// 人没在一个完整的包里边
	}

	private Point person;// 坐标点的位置
	private int height, width;// 数组的宽度和高度
	private static final byte BRICK = 0x01, BOX = 0x2, DEST = 0x10,
			PERSON = 0x20, PERSONDERECTMASK = 0x0C;
	private static final byte PERSON_UP = 0x00, PERSON_LEFT = 0x4,
			PERSON_DOWN = 0x8, PERSON_RIGHT = 0x0C;
	private byte[][] m_array;// 用来存地图的数组,0表示什么都没有,0x01为砖头,0x02箱子,0x10目标的位置,0x20人的位置

	/**
	 * 对地图进行优化,主要是为了去掉周围没用的空格,和长宽反向
	 * 
	 * @param map
	 * @return
	 */
	public static Boxmap optimization(Boxmap map) {
		byte[][] array = map.m_array;
		int top, bottom, left, right;
		int width = map.width;
		int height = map.height;
		top: for (top = 0; top < height; top++) {
			for (int x = 0; x < width; x++) {
				if (!map.isEmpty(x, top)) {
					break top;
				}
			}
		}
		bottom:for(bottom=height-1;bottom >=0;bottom--){
			for(int x=0;x < width;x++){
				if(!map.isEmpty(x,bottom)){
					break bottom;
				}
			}
		}
		left:for(left=0;left < width;left++){
			for(int y=0;y < height;y++){
				if(!map.isEmpty(left,y)){
					break left;
				}
			}
		}
		right:for(right=width-1;right >=0;right--){
			for(int y=0;y < height;y++){
				if(!map.isEmpty(right,y)){
					break right;
				}
			}
		}
		height = bottom - top +1;
		width = right - left + 1;
		byte [][] tmp = new byte[height][width];
		for(int i = top;i <= bottom;i++){
			System.arraycopy(array[i], left, tmp[i-top], 0, right-left + 1);
		}
		if(width > height){//进行转置处理
			byte[][] tmp1 = new byte[width][height];
			int w = tmp1[0].length;
			int h = tmp1.length;
			for(int x =0;x <w;x++){
				for(int y=0; y < h;y++){
					tmp1[y][x] = tmp[height-1-x][y];
				}
			}
			tmp = tmp1;
		}
		return new Boxmap(tmp);
	}

	/**
	 * 检查地图是否为合法的地图
	 * 
	 * @return
	 */
	public int checkMapIsValid() {
		if (person == null) {
			return MapCheckErrorCode.NOPERSON;
		}
		int boxCount = this.getBoxCount();
		if (boxCount == 0) {
			return MapCheckErrorCode.BOXISEMPTY;
		}
		int destCount = this.getDestCount();
		if (destCount != boxCount) {
			return MapCheckErrorCode.BOXNOTEQUALSDEST;
		}
		// 检查是否是否是封闭的,即石头能围成一个空心的圆环
		// 检查方法为找到所有的相连的空节点
		List<List<Point>> emptyList = new ArrayList<List<Point>>();
		for (int y = 0; y < m_array.length; y++) {
			for (int x = 0; x < m_array[y].length; x++) {
				if (!isBrick(x, y)) {// 判断是否为砖头
					if (!isInList(emptyList, new Point(x, y))) {
						List<Point> pointList = new ArrayList<Point>();
						getTheEmptyList(pointList, new Point(x, y));
						emptyList.add(pointList);
					}
				}
			}
		}
		// 检查所有列表是否为闭合的，如果非闭合则从列表中删除
		Iterator<List<Point>> itr = emptyList.iterator();
		while (itr.hasNext()) {
			List<Point> pointList = itr.next();
			if (!isClosedList(pointList)) {
				itr.remove();
			}
		}
		// 检查闭合列表的个数,如果为空则返回错误
		if (emptyList.isEmpty()) {
			return MapCheckErrorCode.PATHNOTCLOSED;
		}
		// 检查箱子，结果，人是否在一个闭包里边,找出人所在的闭包
		List<Point> checkList = findList(emptyList, person);
		if (checkList == null) {
			return MapCheckErrorCode.NOTINONECLOSED;
		}
		// 检查箱子是否在这个闭包里
		int tmp_boxCount = 0, tmp_destCount = 0;
		for (Point temp : checkList) {
			int x = temp.getX(), y = temp.getY();
			if (isBox(x, y)) {
				tmp_boxCount++;
			}
			if (isDest(x, y)) {
				tmp_destCount++;
			}
		}
		if (tmp_boxCount != getBoxCount() || tmp_destCount != getDestCount()) {
			return MapCheckErrorCode.NOTINONECLOSED;
		}
		return MapCheckErrorCode.SUCCESS;
	}

	// 获得某个节点存在的闭包
	private List<Point> findList(List<List<Point>> emptyList, Point point) {
		for (List<Point> pointList : emptyList) {
			if (isInlist_a(pointList, point)) {
				return pointList;
			}
		}
		return null;
	}

	// 检查列表是否为闭合的闭包
	private boolean isClosedList(List<Point> list) {
		for (Point point : list) {
			if (point.getX() == 0 || point.getY() == 0
					|| point.getX() == width - 1 || point.getY() == height - 1) {
				return false;
			}
		}
		return true;
	}

	// 递归求出和空白节点所有相连的列表
	private void getTheEmptyList(List<Point> list, Point begin) {
		if (isInlist_a(list, begin)) {
			return;
		}
		list.add(begin);
		int m_x = begin.getX();
		int m_y = begin.getY();
		if (m_x - 1 >= 0 && !isBrick(m_x - 1, m_y)) {// 向左遍历
			getTheEmptyList(list, new Point(m_x - 1, m_y));
		}
		if (m_x + 1 <= width - 1 && !isBrick(m_x + 1, m_y)) {// 向右遍历
			getTheEmptyList(list, new Point(m_x + 1, m_y));
		}
		if (m_y - 1 >= 0 && !isBrick(m_x, m_y - 1)) {// 向上遍历
			getTheEmptyList(list, new Point(m_x, m_y - 1));
		}
		if (m_y + 1 <= height - 1 && !isBrick(m_x, m_y + 1)) {// 向下遍历
			getTheEmptyList(list, new Point(m_x, m_y + 1));
		}
	}

	// 判断是否在指定的列表中
	private boolean isInList(List<List<Point>> emptyList, Point temp) {
		for (List<Point> tempList : emptyList) {
			if (isInlist_a(tempList, temp)) {
				return true;
			}
		}
		return false;
	}

	private boolean isInlist_a(List<Point> list, Point tmp) {
		for (Point point : list) {
			if (point.getX() == tmp.getX() && point.getY() == tmp.getY()) {
				return true;
			}
		}
		return false;
	}

	/**
	 * 获得目的点的个数
	 * 
	 * @return
	 */
	public int getDestCount() {
		int count = 0;
		for (int i = 0; i < height; i++) {
			for (int ii = 0; ii < width; ii++) {
				if (isDest(m_array[i][ii])) {
					count++;
				}
			}
		}
		return count;
	}

	/**
	 * 获得砖头的个数
	 * 
	 * @return
	 */
	public int getBrickCount() {
		int count = 0;
		for (int i = 0; i < height; i++) {
			for (int ii = 0; ii < width; ii++) {
				if (isBrick(m_array[i][ii])) {
					count++;
				}
			}
		}
		return count;
	}

	/**
	 * 获得箱子的个数
	 * 
	 * @return
	 */
	public int getBoxCount() {
		int count = 0;
		for (int i = 0; i < height; i++) {
			for (int ii = 0; ii < width; ii++) {
				if (isBox(m_array[i][ii])) {
					count++;
				}
			}
		}
		return count;
	}

	// 根据数组来计算人所在的坐标
	private Point getPersonByArray() {
		for (int i = 0; i < height; i++) {
			for (int ii = 0; ii < width; ii++) {
				if (isPerson(m_array[i][ii])) {
					return new Point(ii, i);
				}
			}
		}
		return null;
	}

	/**
	 * 复制出来一份地图
	 * 
	 * @param boxmap
	 * @return
	 */
	public static Boxmap copy(Boxmap boxmap) {
		byte[][] byteArray = new byte[boxmap.height][boxmap.width];
		int index = 0;
		for (byte[] tmpbyte : byteArray) {
			System.arraycopy(boxmap.m_array[index], 0, tmpbyte, 0,
					boxmap.m_array[index].length);
			index++;
		}
		return new Boxmap(byteArray);
	}

	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("/****************************/\n");
		for (int y = 0; y < this.m_array.length; y++) {
			byte[] tmp = this.m_array[y];
			if (y != 0) {
				sb.append("\n");
			}
			for (int x = 0; x < tmp.length; x++) {
				if (x != 0) {
					sb.append(",");
					sb.append(tmp[x]);
				}
			}
		}
		sb.append("\n/****************************/");
		return sb.toString();
	}

	/**
	 * 构造地图
	 * 
	 * @param x
	 * @param y
	 */
	public Boxmap(int x, int y) {
		m_array = new byte[y][x];
		this.width = x;
		this.height = y;
	}

	public Boxmap(byte[][] array) {
		m_array = array;
		height = array.length;
		if (height == 0) {
			width = 0;
		} else {
			width = m_array[0].length;
		}
		person = getPersonByArray();
	}

	/**
	 * 判断人是否状态向上
	 * 
	 * @param x
	 * @param y
	 * @return
	 */
	public boolean isPersonUp(int x, int y) {
		return checkPresonDerect(x, y, PERSON_UP);
	}

	/**
	 * 判断人的状态是否向上
	 * 
	 * @return
	 */
	public boolean isPersonUp() {
		return isPersonUp(person.getX(), person.getY());
	}

	/**
	 * 判断人是否向下
	 * 
	 * @param x
	 * @param y
	 * @return
	 */
	public boolean isPersonDown(int x, int y) {
		return checkPresonDerect(x, y, PERSON_DOWN);
	}

	/**
	 * 判断人是否向向下
	 * 
	 * @return
	 */
	public boolean isPersonDown() {
		return isPersonDown(person.getX(), person.getY());
	}

	/**
	 * 判断是否向左
	 * 
	 * @param x
	 * @param y
	 * @return
	 */
	public boolean isPersonLeft(int x, int y) {
		return checkPresonDerect(x, y, PERSON_LEFT);
	}

	/**
	 * 判断是否向左
	 * 
	 * @return
	 */
	public boolean isPersonLeft() {
		return isPersonLeft(person.getX(), person.getY());
	}

	/**
	 * 判断是否向右
	 * 
	 * @param x
	 * @param y
	 * @return
	 */
	public boolean isPersonRight(int x, int y) {
		return checkPresonDerect(x, y, PERSON_RIGHT);
	}

	/**
	 * 判断是否向右
	 * 
	 * @return
	 */
	public boolean isPersonRight() {
		return isPersonRight(person.getX(), person.getY());
	}

	private boolean checkPresonDerect(int x, int y, byte mask) {
		byte tmp = getValue(x, y);
		if ((tmp & PERSONDERECTMASK) == mask) {
			return true;
		} else {
			return false;
		}
	}

	// 获得坐标点的值
	private byte getValue(int x, int y) {
		return m_array[y][x];
	}

	// 设置坐标点的值
	private void putValue(int x, int y, int value) {
		m_array[y][x] = (byte) (value & 0xff);
	}

	/**
	 * 设置砖头的位置
	 * 
	 * @param x
	 * @param y
	 */
	public boolean setBrick(int x, int y) {
		if (x < 0 || x > width - 1 || y < 0 || y > height - 1) {
			return false;
		}
		byte value = getValue(x, y);
		if (!isEmpty(value)) {
			return false;
		}
		putValue(x, y, BRICK);
		return true;
	}

	/**
	 * 设置箱子的位置
	 * 
	 * @param x
	 * @param y
	 * @return
	 */
	public boolean setBox(int x, int y) {
		if (x < 0 || x > width - 1 || y < 0 || y > height - 1) {
			return false;
		}
		byte value = getValue(x, y);
		if (!isEmpty(value) && !isDest(value)) {
			return false;
		}
		putValue(x, y, (value | BOX));
		return true;
	}

	/**
	 * 清除箱子的位置
	 * 
	 * @param x
	 * @param y
	 * @return
	 */
	public boolean clearBox(int x, int y) {
		byte value = getValue(x, y);
		if (!isBox(value)) {
			return false;
		}
		putValue(x, y, (value & (~BOX)));
		return true;
	}

	/**
	 * 清除目的地址的位置
	 * 
	 * @param x
	 * @param y
	 * @return
	 */
	public boolean clearDest(int x, int y) {
		byte value = getValue(x, y);
		if (!isDest(value)) {
			return false;
		}
		putValue(x, y, (value & (~DEST)));
		return true;
	}

	/**
	 * 清除人的位置
	 * 
	 * @param x
	 * @param y
	 * @return
	 */
	public boolean clearPerson(int x, int y) {
		byte value = getValue(x, y);
		if (!isPerson(value)) {
			return false;
		}
		putValue(x, y, (value & (~PERSON) & (~PERSONDERECTMASK)));
		return true;
	}

	/**
	 * 清除位置上的砖头
	 * 
	 * @param x
	 * @param y
	 * @return
	 */
	public boolean clearBrick(int x, int y) {
		byte value = getValue(x, y);
		if (!isBrick(value)) {
			return false;
		}
		putValue(x, y, (value & (~BRICK)));
		return true;
	}

	/**
	 * 设置目的地址
	 * 
	 * @param x
	 * @param y
	 * @return
	 */
	public boolean setDest(int x, int y) {
		if (x < 0 || x > width - 1 || y < 0 || y > height - 1) {
			return false;
		}
		byte value = getValue(x, y);
		if (!isEmpty(value) && !isBox(value) && !isPerson(value)) {
			return false;
		}
		putValue(x, y, (value | DEST));
		return true;
	}

	/**
	 * 设置人的目的地址
	 * 
	 * @param x
	 * @param y
	 * @return
	 */
	public boolean setPerson(int x, int y) {
		setPerson(x, y, PERSON_UP);
		return true;
	}

	private boolean setPerson(int x, int y, int status) {
		if (x < 0 || x > width - 1 || y < 0 || y > height - 1) {
			return false;
		}
		byte value = getValue(x, y);
		if (!isEmpty(value) && !isDest(value)) {
			return false;
		}
		// putValue(x, y, (value | PERSON | PERSONDERECTMASK) & status);
		putValue(x, y, (value | PERSON | PERSONDERECTMASK)
				& (status | (~PERSONDERECTMASK)));
		if (person != null) {
			clearPerson(person.getX(), person.getY());
		}
		person = new Point(x, y);// 设置人的坐标
		return true;
	}

	/**
	 * 判断位置是否为砖头
	 * 
	 * @param x
	 * @param y
	 * @return
	 */
	public boolean isBrick(int x, int y) {
		byte value = getValue(x, y);
		return isBrick(value);
	}

	/**
	 * 判断所给的值是否是砖头
	 * 
	 * @param value
	 * @return
	 */
	public boolean isBrick(byte value) {
		if (value == BRICK) {
			return true;
		} else
			return false;
	}

	/**
	 * 判断所在的位置是否为空
	 * 
	 * @param x
	 * @param y
	 * @return
	 */
	public boolean isEmpty(int x, int y) {
		byte value = getValue(x, y);
		return isEmpty(value);
	}

	/**
	 * 判断所给的值是否为空
	 * 
	 * @param value
	 * @return
	 */
	public boolean isEmpty(byte value) {
		if (value == 0) {
			return true;
		} else
			return false;
	}

	/**
	 * 判断所在的位置是否为目的地
	 * 
	 * @param x
	 * @param y
	 * @return
	 */
	public boolean isDest(int x, int y) {
		byte value = getValue(x, y);
		return isDest(value);
	}

	/**
	 * 判断目的号码是否为目的
	 * 
	 * @param value
	 * @return
	 */
	public boolean isDest(byte value) {
		if ((value & DEST) != 0) {
			return true;
		} else
			return false;
	}

	/**
	 * 判断目标值是否为箱子
	 * 
	 * @param value
	 * @return
	 */
	public boolean isBox(byte value) {
		if ((value & BOX) != 0) {
			return true;
		} else
			return false;
	}

	/**
	 * 判断所在的位置是否是否为箱子
	 * 
	 * @param x
	 * @param y
	 * @return
	 */
	public boolean isBox(int x, int y) {
		byte value = getValue(x, y);
		return isBox(value);
	}

	/**
	 * 判断所在的位置是否为人
	 * 
	 * @param value
	 * @return
	 */
	public boolean isPerson(byte value) {
		if ((value & PERSON) != 0) {
			return true;
		} else
			return false;
	}

	/**
	 * 判断所在的位置是否为人
	 * 
	 * @param x
	 * @param y
	 * @return
	 */
	public boolean isPerson(int x, int y) {
		byte value = getValue(x, y);
		return isPerson(value);
	}

	/**
	 * 获得地图的高度
	 * 
	 * @return
	 */
	public int getHeight() {
		return height;
	}

	/**
	 * 获得地图的宽度
	 * 
	 * @return
	 */
	public int getWidth() {
		return width;
	}

	/**
	 * 地图向上行走
	 * 
	 * @return
	 */
	public boolean up() {
		int x = person.getX();
		int y = person.getY();
		y--;
		if (isEmpty(x, y)) {// 上方为空
			setPerson(x, y, PERSON_UP);
			return true;
		} else if (isBrick(x, y)) {// 上方是砖头不能移动
			return false;
		} else if (isBox(x, y)) {// 上方是箱子,判断箱子上上方是否为"砖头","箱子",是的话不能移动,否的话可以移动
			if (isBox(x, y - 1) || isBrick(x, y - 1)) {
				return false;
			} else {
				setBox(x, y - 1);
				clearBox(x, y);
				setPerson(x, y, PERSON_UP);
				return true;
			}
		} else {// 是dest,可以移动
			setPerson(x, y, PERSON_UP);
			return true;
		}
	}

	/**
	 * 地图往下走
	 * 
	 * @return
	 */
	public boolean down() {
		int x = person.getX();
		int y = person.getY();
		y++;
		if (isEmpty(x, y)) {// 下方为空
			setPerson(x, y, PERSON_DOWN);
			return true;
		} else if (isBrick(x, y)) {// 下方为砖头,不能移动
			return false;
		} else if (isBox(x, y)) {// 下方为箱子,判断箱子下下方是否为"砖头","箱子",是的话不能移动,否的话可以移动
			if (isBox(x, y + 1) || isBrick(x, y + 1)) {
				return false;
			} else {
				setBox(x, y + 1);
				clearBox(x, y);
				setPerson(x, y, PERSON_DOWN);
				return true;
			}
		} else {// 是dest可以移动
			setPerson(x, y, PERSON_DOWN);
			return true;
		}
	}

	/**
	 * 地图往左走
	 * 
	 * @return
	 */
	public boolean left() {
		int x = person.getX();
		int y = person.getY();
		x--;
		if (isEmpty(x, y)) {// 左方为空
			setPerson(x, y, PERSON_LEFT);
			return true;
		} else if (isBrick(x, y)) {// 左方为砖头,不能移动
			return false;
		} else if (isBox(x, y)) {// 左方为箱子,判断箱子左左方是否为"砖头","箱子",是的话不能移动,否的话可以移动
			if (isBox(x - 1, y) || isBrick(x - 1, y)) {
				return false;
			} else {
				setBox(x - 1, y);
				clearBox(x, y);
				setPerson(x, y, PERSON_LEFT);
				return true;
			}
		} else {// 是dest可以移动
			setPerson(x, y, PERSON_LEFT);
			return true;
		}
	}

	/**
	 * 地图往右走
	 * 
	 * @return
	 */
	public boolean right() {
		int x = person.getX();
		int y = person.getY();
		x++;
		if (isEmpty(x, y)) {// 右方为空
			setPerson(x, y, PERSON_RIGHT);
			return true;
		} else if (isBrick(x, y)) {// 右方为砖头,不能移动
			return false;
		} else if (isBox(x, y)) {// 右方为箱子,判断箱子左左方是否为"砖头","箱子",是的话不能移动,否的话可以移动
			if (isBox(x + 1, y) || isBrick(x + 1, y)) {
				return false;
			} else {
				setBox(x + 1, y);
				clearBox(x, y);
				setPerson(x, y, PERSON_RIGHT);
				return true;
			}
		} else {// 是dest可以移动
			setPerson(x, y, PERSON_RIGHT);
			return true;
		}
	}

	/**
	 * 是否成功,判定条件:所有目标的节点同时还是箱子的节点
	 * 
	 * @return
	 */
	public boolean isSuccess() {
		for (int i = 0; i < height; i++) {
			for (int ii = 0; ii < width; ii++) {
				if (isDest(m_array[i][ii]) && !isBox(m_array[i][ii])) {
					return false;
				}
			}
		}
		return true;
	}

	/**
	 * 判断是否为外部empty节点,判断方法为左右排序,是否一直为空
	 * 
	 * @param x
	 * @param y
	 * @return
	 */
	public boolean isOuterEmpty(int x, int y) {
		boolean flag = true;
		for (int i = x; i >= 0; i--) {
			if (!isEmpty(i, y)) {
				flag = false;
				break;
			}
		}
		if (flag) {
			return true;
		}
		flag = true;
		for (int i = x; i < width; i++) {
			if (!isEmpty(i, y)) {
				flag = false;
				break;
			}
		}
		if (flag) {
			return true;
		}
		flag = true;
		for (int i = y; i >= 0; i--) {
			if (!isEmpty(x, i)) {
				flag = false;
				break;
			}
		}
		if (flag) {
			return true;
		}
		flag = true;
		for (int i = y; i < height; i++) {
			if (!isEmpty(x, i)) {
				flag = false;
				break;
			}
		}
		if (flag) {
			return true;
		}
		return false;
	}

	/**
	 * 判断是否为内部空节点
	 * 
	 * @param x
	 * @param y
	 * @return
	 */
	public boolean isInnerEmpty(int x, int y) {
		return !isOuterEmpty(x, y);
	}

	/**
	 * 把地图格式化为二维数组
	 * 
	 * @return
	 */
	public byte[][] toByte() {
		return this.m_array;
	}

	public Point getPerson() {
		return person;
	}

	/**
	 * 回退上一步的操作
	 * 
	 * @param step1
	 * @param step2
	 */
	public void revertPreStep(Step step1, Step step2) {
		int person_x = person.getX();
		int person_y = person.getY();
		switch (step1.getStatus()) {
		case Step.DOWN:
			this.setPerson(person_x, person_y - 1, step2);
			if (step1.isPushBox()) {
				this.setBox(person_x, person_y);
				this.clearBox(person_x, person_y + 1);
			}
			break;
		case Step.UP:
			this.setPerson(person_x, person_y + 1, step2);
			if (step1.isPushBox()) {
				this.setBox(person_x, person_y);
				this.clearBox(person_x, person_y - 1);
			}
			break;
		case Step.LEFT:
			this.setPerson(person_x + 1, person_y, step2);
			if (step1.isPushBox()) {
				this.setBox(person_x, person_y);
				this.clearBox(person_x - 1, person_y);
			}
			break;
		case Step.RIGHT:
			this.setPerson(person_x - 1, person_y, step2);
			if (step1.isPushBox()) {
				this.setBox(person_x, person_y);
				this.clearBox(person_x + 1, person_y);
			}
			break;
		}
	}

	private void setPerson(int x, int y, Step step) {
		if (step == null) {
			this.setPerson(x, y, PERSON_UP);
		} else {
			switch (step.getStatus()) {
			case Step.DOWN:
				this.setPerson(x, y, PERSON_DOWN);
				break;
			case Step.UP:
				this.setPerson(x, y, PERSON_UP);
				break;
			case Step.LEFT:
				this.setPerson(x, y, PERSON_LEFT);
				break;
			case Step.RIGHT:
				this.setPerson(x, y, PERSON_RIGHT);
				break;
			}
		}
	}
}
